package core.util;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author songduk park
 * 
 */
public class DateUtil {

	public static int getHour() {
		Calendar calendar = Calendar.getInstance();
		return calendar.get(Calendar.HOUR_OF_DAY);
	}

	public static int getYear() {
		Calendar calendar = Calendar.getInstance();
		return calendar.get(Calendar.YEAR);
	}

	public static int getMonth() {
		Calendar calendar = Calendar.getInstance();
		return calendar.get(Calendar.MONTH) + 1;
	}

	public static Date convertStringToDate(String date) {
		if (date == null || date.length() < 8)
			return null;

		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		Date newDate = null;
		try {
			newDate = df.parse(date.replace('/', '-'));

		} catch (ParseException e) {
			e.printStackTrace();
		}
		return newDate;
	}

	public static Date convertMMddYYYYToDate(String date) {
		if (date == null || date.length() < 8)
			return null;

		DateFormat df = new SimpleDateFormat("MM-dd-yyyy");
		Date newDate = null;
		try {
			newDate = df.parse(date.replace('/', '-'));

		} catch (ParseException e) {
			System.out.println(e.getMessage());
		}
		return newDate;
	}

	public static Date convertYYYYMMDDToDate(String date) {
		if (date == null || date.length() < 8)
			return null;

		DateFormat df = new SimpleDateFormat("yyyyMMdd");
		Date newDate = null;
		try {
			newDate = df.parse(date);

		} catch (ParseException e) {
			System.out.println(e.getMessage());
		}
		return newDate;
	}

	public static String convertDateToString(Date date) {
		if (date == null)
			return "";
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
		return df.format(date);
	}

	public static String getYYYYmmDD() {
		return convertDateToString(new Date());
	}

	public static int getWeek() {
		Calendar calendar = Calendar.getInstance();
		return calendar.get(Calendar.WEEK_OF_YEAR);
	}
}
